import Vue from 'vue';
import Router from 'vue-router';
const _import = require('./_import_' + process.env.NODE_ENV);
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading


/* layout */
import Layout from '../views/layout/Layout';
/* login */
const Login = _import('login/login');

/* home */
const home = _import('home/index');

/* error page */
const Err404 = _import('404');

// 创建文件
// const manageFound = _import('apply/management/found');

Vue.use(Router);

/**
 * 此处的map不需要做权限,通配
 * icon : the icon show in the sidebar
 * hidden : if `hidden:true` will not show in the sidebar
 * redirect : if `redirect:noredirect` will not redirct in the levelbar
 * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
 * meta : `{ role: ['admin'] }`  will control the page role
 **/
export const constantRouterMap = [

    { path: '/login', component: Login, hidden: true },
    { path: '/404', component: Err404, hidden: true },
    {
        path: '/',
        component: Layout,
        redirect: '/home',
        hidden: true,
    },
    {
        path: '/home',
        component: Layout,
        redirect: '/home/index',
        icon: 'index-home',
        noDropdown: true,
        children: [
            { path: 'index', component: _import('home/index'), name: '平台主页' }
        ]
    }
]

export default new Router({
    // mode: 'history', //后端支持可开
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
});

/**
 * 权限菜单map
 * meta:{} 元数据信息的role路径和系统功能菜单维护的url一致,否则,无法筛选
 */
export const asyncRouterMap = [{
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    name: '用户中心',
    icon: 'usercenter',
    meta: { role: ['/userBase'] },
    children: [{
        path: '/user',
        component: _import('user/user/index'),
        redirect: 'user/user/menu',
        name: '用户管理',
        icon: 'uesr-manage',
        meta: { role: ['/userBase/user'] },
        children: [
            { path: 'menu', meta: { role: ['/userBase/user/menu'] }, component: _import('user/user/menu'), name: '菜单维护' },
            { path: 'role', meta: { role: ['/userBase/user/role'] }, component: _import('user/user/role'), name: '角色维护' },
            { path: 'user', meta: { role: ['/userBase/user/user'] }, component: _import('user/user/user'), name: '用户维护' },
            { path: 'news', meta: { role: ['/userBase/user/news'] }, component: _import('user/user/news'), name: '我的信息' }
        ]
    },
    {
        path: '/infrastructure',
        component: _import('user/infrastructure/index'),
        redirect: 'user/infrastructure/function',
        name: '设施管理',
        icon: 'sheshi',
        meta: { role: ['/userBase/infrastructure'] },
        children: [
            { path: 'function', meta: { role: ['/userBase/infrastructure/group'] }, component: _import('user/infrastructure/function'), name: '物理分组' },
            { path: 'node', meta: { role: ['/userBase/infrastructure/node'] }, component: _import('user/infrastructure/node'), name: '节点维护' }
        ]
    },
    {
        path: '/team',
        component: _import('user/team/function'),
        icon: 'team',
        noDropdown: true,
        meta: { role: ['/userBase/team'] },
        children: [
            { path: 'function', meta: { role: ['/userBase/team/function'] }, component: _import('user/team/function'), name: '团队管理' }
        ]
    }
    ]
},
{
    path: '/apply',
    component: Layout,
    redirect: 'noredirect',
    name: '应用中心',
    icon: 'yingyong',
    meta: { role: ['/apply'] },
    children: [{
        path: '/apply/management',
        component: _import('apply/management/index'),
        icon: 'yingyong',
        noDropdown: true,
        meta: { role: ['/apply/management'] },
        children: [
            { path: 'app_page', meta: { role: ['/apply/management/app_page'] }, component: _import('apply/management/app_page'), name: '应用管理' },
            { path: 'app_create', meta: { role: ['/apply/management/app_create'] }, component: _import('apply/management/app_create'), name: '部署方式' },
            { path: 'app_create/compose_file', meta: { role: ['/apply/management/app_create/compose_file'] }, component: _import('apply/management/compose_file'), name: '编排文件' },
            { path: 'app_create/image_repertory', meta: { role: ['/apply/management/app_create/image_repertory'] }, component: _import('apply/management/image_repertory'), name: '镜像仓库' },
            { path: 'app_manage', meta: { role: ['/apply/management/app_manage'] }, component: _import('apply/management/app_manage'), name: '应用详细' },
        ]
    },
    {
        path: '/apply/mirror',
        component: _import('apply/mirror/index'),
        icon: 'jingxiang',
        noDropdown: true,
        meta: { role: ['/apply/mirror'] },
        children: [
            { path: 'manage', meta: { role: ['/apply/mirror/manage'] }, component: _import('apply/mirror/index'), name: '镜像管理' }
        ]
    },
    {
        path: '/apply/store',
        component: _import('apply/store/index'),
        redirect: 'apply/store/type',
        name: '应用商店',
        icon: 'store',
        meta: { role: ['/apply/store'] },
        children: [
            { path: 'type', meta: { role: ['/apply/store/type'] }, component: _import('apply/store/type'), name: '应用类型' },
            { path: 'manage', meta: { role: ['/apply/store/manage'] }, component: _import('apply/store/manage'), name: '商店管理' },
            { path: 'shop', meta: { role: ['/apply/store/shop'] }, component: _import('apply/store/shop'), name: '应用商店' },
        ]
    },
    {
        path: '/apply/service',
        component: _import('apply/service/configmap'),
        icon: 'fuwupeizhi',
        noDropdown: true,
        meta: { role: ['/apply/service'] },
        children: [
            { path: 'configmap', meta: { role: ['/apply/service/configmap'] }, component: _import('apply/service/configmap'), name: '服务配置' }
        ]
    },
    {
        path: '/apply/storage',
        component: _import('apply/storage/management'),
        icon: 'storage',
        noDropdown: true,
        meta: { role: ['/apply/storage'] },
        children: [
            { path: 'management', meta: { role: ['/apply/storage/management'] }, component: _import('apply/storage/management'), name: '存储管理' }
        ]
    },
    {
        path: '/apply/load',
        component: _import('apply/load/index'),
        redirect: 'apply/load/services',
        name: '负载均衡',
        icon: 'load',
        meta: { role: ['/apply/load'] },
        children: [
            { path: 'services', meta: { role: ['/apply/load/services'] }, component: _import('apply/load/services'), name: '服务管理' },
            { path: 'domain', meta: { role: ['/apply/load/domain'] }, component: _import('apply/load/domain'), name: '域名访问' },
        ]
    },
    ]
},
{
    path: '/cicd',
    component: Layout,
    redirect: 'noredirect',
    name: 'CICD中心',
    icon: 'task',
    meta: { role: ['/task'] },
    children: [{
        path: '/cicd/codeRep',
        component: _import('cicd/codeRep'),
        icon: 'manager',
        noDropdown: true,
        meta: { role: ['/cicd/codeRep'] },
        children: [
            { path: 'codeRep', meta: { role: ['/cicd/codeRep/management'] }, component: _import('cicd/codeRep'), name: '代码仓库' }
        ]
    },
    {
        path: '/cicd/pipeline',
        component: _import('cicd/pipeline'),
        icon: 'manager',
        noDropdown: true,
        meta: { role: ['/cicd/pipeline'] },
        children: [
            { path: 'pipeline', meta: { role: ['/cicd/pipeline/management'] }, component: _import('cicd/pipeline'), name: '流水线' }
        ]
    }
    ]
},
{
    path: '/monitoring',
    component: Layout,
    redirect: 'noredirect',
    name: '监控中心',
    icon: 'jiankong',
    meta: { role: ['/monitoring'] },
    children: [{
        path: '/monitoring/node',
        component: _import('monitoring/node/function'),
        icon: 'jiedian',
        noDropdown: true,
        meta: { role: ['/monitoring/node'] },
        children: [
            { path: 'function', meta: { role: ['/monitoring/node/management'] }, component: _import('monitoring/node/function'), name: '节点监控' }
        ]
    },

    {
        path: '/monitoring/application',
        component: _import('monitoring/plateform/function'),
        icon: 'apply',
        noDropdown: true,
        meta: { role: ['/monitoring/application'] },
        children: [
            { path: 'function', meta: { role: ['/monitoring/application/management'] }, component: _import('monitoring/plateform/function'), name: '应用监控' }
        ]
    }
    ]
},
{
    path: '/diary',
    component: Layout,
    redirect: 'noredirect',
    name: '日志中心',
    icon: 'dairy',
    meta: { role: ['/diary'] },
    children: [{
        path: '/diary/operation',
        component: _import('diary/operation/index'),
        icon: 'operate',
        noDropdown: true,
        meta: { role: ['/diary/operation'] },
        children: [
            { path: 'index', meta: { role: ['/diary/operation/index'] }, component: _import('diary/operation/index'), name: '操作审计' }
        ]
    },
    {
        path: '/diary/paltform',
        component: _import('diary/paltform/index'),
        icon: 'ziliaoshouce',
        noDropdown: true,
        meta: { role: ['/diary/paltform'] },
        children: [
            { path: 'index', meta: { role: ['/diary/paltform/index'] }, component: _import('diary/paltform/index'), name: '平台日志' }
        ]
    },
    {
        path: '/diary/use',
        component: _import('diary/use/index'),
        icon: 'yingyongriji',
        noDropdown: true,
        meta: { role: ['/diary/use'] },
        children: [
            { path: 'index', meta: { role: ['/diary/use/index'] }, component: _import('diary/use/index'), name: '应用日志' }
        ]
    },
    ]
},
{
    path: '/task',
    component: Layout,
    redirect: 'noredirect',
    name: '任务中心',
    icon: 'task',
    meta: { role: ['/task'] },
    children: [{
        path: '/task/manager',
        component: _import('task/manager'),
        icon: 'manager',
        noDropdown: true,
        meta: { role: ['/task/manager'] },
        children: [
            { path: 'manager', meta: { role: ['/task/manager/management'] }, component: _import('task/manager'), name: '任务管理' }
        ]
    },
    {
        path: '/task/warning',
        component: _import('task/warning'),
        icon: 'warning',
        noDropdown: true,
        meta: { role: ['/task/warning'] },
        children: [
            { path: 'warning', meta: { role: ['/task/warning/management'] }, component: _import('task/warning'), name: '预警管理' }
        ]
    }
    ]
},

{ path: '*', redirect: '/404', hidden: true }
];
